// pages/buyed/buyed.js
const db = wx.cloud.database();
Page({
  data:{
    newList:{},
    hid:false,
    _id:''
  },
  onLoad: function (options) {
    // 再通过setData更改Page()里面的data，动态更新页面的数据
    var str = options.list;
    console.log(str);
    var newList = str.split(",").map((str,i,arr)=>{
      //商品必须是二个字段
      if(i%2===0){                               
        return {name:arr[i],number:arr[i+1]}
      }
      return ""
    }).filter(item=>item);
    console.log(newList);
    const newArr = newList.splice(-1);
    var hid = this.data.hid;
    var _id = this.data._id;
     _id = newArr[0].name;
    if (newArr[0].number === 'true'){
      hid = true;
     }
    this.setData({
      newList,
      hid,
      _id,
    })
},
cancel:function(){
  let that = this;
  var _id = that.data._id;
  var hid = that.data.hid;
  db.collection('dsbsaled').doc(_id).update({      
    data: {
      'order': false
    },  success: function() {
      that.setData({
       hid:false
      }); 
      wx.showModal({
        title: '',
        content: '订单已取消！',
        showCancel: false,
        success (res) {
          if (res.confirm) {
            wx.switchTab({
              url: '../home/home'
            })  
          } else if (res.cancel) {    
      }
    }
  })
     

    },fail:function(){
      wx.showToast({
        title: '取消失败！查网络',
        icon: 'error',
        duration: 3000
      })
      注意
    }
  })
}
})